function NotchBeam
clc
%close all
addpath('../');
addpath('../../');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% read mesh
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
projDir = '/home/hbui/kratos_janosch';
%coarse (structure) mesh
projName = 'notchbeam.gid';
fn = [projDir '/' projName '/' 'mesh1.msh'];

mg = fem2.gid.GidMeshGenerator(fn);
mesh = mg.getMesh(2);
mesh.setNumberOfFields(2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% conditions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
du = 1;
% lambda = 0.4:0.01:0.7;
% lambda = 0.4:0.1:0.7;
lambda = 0.4:0.1:1;
meshUtil = fem2.MeshUtilities(mesh);
c1 = fem2.Constraint([0 0]);
c2 = fem2.Constraint([0 1]);
c3 = fem2.Constraint([0 1]);
c3.setValue(0,du);
edge1 = meshUtil.seekNodesOnSurface(1,0,0);
edge2 = meshUtil.seekNodesOnSurface(1,0,-2);
mesh.setConstraint(c2,edge1);
meshUtil.seekNode([0 0]).setConstraint(c1);
mesh.setConstraint(c3,edge2);
% plotMesh(mesh);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% element declaration
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
M = fem2.Model(mesh);
nf = mesh.countFaces();
E = 2;
nu = 0.3;
H = -1;
ft = 0.91;
C = C_plane_stress(E,nu);
for i=1:nf
    e = fem2.MatlabStructuralElement(mesh.getFace(i-1));
    M.addElement(e);
    %create struct to contain element state variables
    es = createElementContainer(C,H,ft);
    elements(i) = es;
end
%deactivate and activate elements
% for i=1:nf
%     c = computeFaceCenter(mesh.getFace(i-1));
%     if (c(1)>=0 && c(1)<=0.6 && c(2)>=-0.6 && c(2)<=-0.4)
%         elements(i).isActivated = 1;
%     else
%         elements(i).isActivated = 0;
%     end
% end

for i=1:edge1.size()
    edge1nodes(i) = edge1.get(i-1).getId();
end

postProcessInfo.infoList = {'resistant force','check sigma1','crack opening Linder'};
postProcessInfo.infoParam = {edge1nodes,[],[]};

[elements,output] = solving_strategy_static_2(elements,M,...
    lambda,50,1e-6,postProcessInfo);

figure
res_node_1(:,:) = -output.resistant_force(:,1,:);
delta = lambda*du;
plot(delta,res_node_1);

plotMeshWithCrack(M,elements,{'trimesh','conditions','id'});
plotDeformedMesh(mesh,1);

rmpath('../');
rmpath('../../');

